package com.engine.jucailinkq.attendance.component.persongroup.web;

import com.engine.jucailinkq.attendance.component.persongroup.service.SchedulingResultsService;
import com.engine.jucailinkq.attendance.component.persongroup.service.impl.SchedulingResultsServiceImpl;
import com.engine.jucailinkq.common.util.ApiReturnTools;
import com.engine.common.util.ParamUtil;
import com.engine.common.util.ServiceUtil;
import lombok.extern.slf4j.Slf4j;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Context;
import java.util.Map;
@Slf4j
public class SchedulingResultsAction {

    private SchedulingResultsService basicsetService = ServiceUtil.getService(SchedulingResultsServiceImpl.class);
    /**
     * 获得排班结果列表查询
     * @return
     */
    @POST
    @Path("/getSchedulingData")
    @Produces({"text/plain"})
    public String getSchedulingData(@Context HttpServletRequest request, @Context HttpServletResponse response) {
        try {
            Map<String,Object> paramMap = ParamUtil.request2Map(request);
            Map<String,Object> dataMap = basicsetService.queryDataTable(paramMap);
            return ApiReturnTools.success(dataMap);
        }catch (Exception e){
            log.error("execute fail,catch error: [{}]",e);
            return ApiReturnTools.error("500","saveApplicableOrganization error");
        }
    }
    /**
     * 出勤结果更改时插入排班结果
     * @return
     */
    @POST
    @Path("/saveScheduleResult")
    @Produces({"text/plain"})
    public String saveScheduleResult(@Context HttpServletRequest request, @Context HttpServletResponse response) {
        try {
            Map<String,Object> paramMap = ParamUtil.request2Map(request);
            Map<String,Object> dataMap = basicsetService.saveScheduleResult(paramMap);
            return ApiReturnTools.success(dataMap);
        }catch (Exception e){
            log.error("execute fail,catch error: [{}]",e);
            return ApiReturnTools.error("500","saveApplicableOrganization error");
        }
    }

    /**
     * 生成排班结果
     * @return
     */
    @POST
    @Path("/generateSchedule")
    @Produces({"text/plain"})
    public String generateSchedule(@Context HttpServletRequest request, @Context HttpServletResponse response) {
        try {
            Map<String,Object> paramMap = ParamUtil.request2Map(request);
            Map<String,Object> dataMap = basicsetService.generateSchedule(paramMap);
            return ApiReturnTools.success(dataMap);
        }catch (Exception e){
            log.error("execute fail,catch error: [{}]",e);
            return ApiReturnTools.error("500","generateSchedule error");
        }
    }
    /**
     * 批量删除排班结果
     * @return
     */
    @POST
    @Path("/deleteBatchSchedule")
    @Produces({"text/plain"})
    public String deleteBatchSchedule(@Context HttpServletRequest request, @Context HttpServletResponse response) {
        try {
            Map<String,Object> paramMap = ParamUtil.request2Map(request);
            Map<String,Object> dataMap = basicsetService.deleteBatchSchedule(paramMap);
            return ApiReturnTools.success(dataMap);
        }catch (Exception e){
            log.error("execute fail,catch error: [{}]",e);
            return ApiReturnTools.error("500","generateSchedule error");
        }
    }

}
